package com.dlb.andorid.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.dlb.andorid.App;
import com.dlb.andorid.R;
import com.dlb.andorid.XContract;
import com.dlb.andorid.XServerMsg;
import com.dlb.andorid.bean.UserInfo;
import com.dlb.andorid.presenter.PointPresenter;
import com.kwan.xframe.mvp.presenter.BasePresenter;
import com.kwan.xframe.mvp.view.activity.BaseCommonActivity;

public class PointActivity extends BaseCommonActivity implements XContract.IPointView {

	PointPresenter mPresenter;

	@Override
	protected BasePresenter getBasePresenter() {
		mPresenter = new PointPresenter(this);
		return mPresenter;
	}

	TextView tv_point, tv_coin, tv_ok;
	EditText et_coin;

	@Override
	protected void initViews() {
		super.initViews();
		tv_point = findViewById(R.id.tv_point);
		tv_coin = findViewById(R.id.tv_coin);
		tv_ok = findViewById(R.id.tv_ok);
		et_coin = findViewById(R.id.et_coin);
		tv_ok.setOnClickListener(this);

	}

	@Override
	protected void initData() {
		showProgress("");
		mPresenter.getUserInfo();
	}

	@Override
	public void onClick(View v) {
		super.onClick(v);
		if (v == tv_ok) {
			String strNum = et_coin.getText().toString();
			if (strNum.isEmpty()) {
				toastMsg("请输入数量");
			} else {
				showProgress("");
				mPresenter.exchange(Long.valueOf(strNum));
			}

		}
	}

	@Override
	protected int getTopViewId() {
		return 0;
	}

	@Override
	protected int getMainViewId() {
		return R.layout.activity_point;
	}

	@Override
	protected int getBottomViewId() {
		return 0;
	}

	@Override
	protected String getTitleTxt() {
		return "积分换金币";
	}

	@Override
	public String getPageName() {
		return null;
	}

	@Override
	public void exchangeSuccess(XServerMsg data) {
		toastMsg("兑换成功");
		mPresenter.getUserInfo();
	}

	@Override
	public void getUserInfoSuccess(UserInfo data) {

		dismissProgress();
		App.mUserInfo = data;
		tv_coin.setText(App.mUserInfo.getGold_coin() + "");
		tv_point.setText(App.mUserInfo.getIntegral_num() + "");
		et_coin.setHint("可以兑换" + (int) (App.mUserInfo.getIntegral_num() * App.mUserInfo.getProportion_integral_gold()) + "金币");
	}
}
